package com.wnxy.c_exec;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class App1 {
    public static void main(String[] args) {
        // Executors.newFixedThreadPool 创建一个指定核心线程数大小的线程池
        // 注意：使用无界队列，容易引起oom内存移除异常
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 1; i < 11; i++) {
            executorService.execute(() -> {
                System.out.println(Thread.currentThread().getName()  + "执行线程start");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "执行线程end");
            });
        }
    }
}
